package cn.javase.base.reflect;

import java.lang.reflect.Field;

public class _07_利用反射获取并设置成员变量的值 {
    public static void main(String[] args) throws Exception {
        Student student = new Student("张三", 18);
        Class<? extends Student> studentClass = student.getClass();
        Field name = studentClass.getDeclaredField("name");
        name.setAccessible(true);
        Object oldValue = name.get(student);
        System.out.println(oldValue); // 获取值
        name.set(student, "李四"); // 设置值
        System.out.println(student);
    }
}
